﻿using System;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000DE RID: 222
	[RequireComponent(typeof(Rigidbody))]
	[RequireComponent(typeof(CapsuleCollider))]
	public abstract class CharacterBase : MonoBehaviour
	{
		// Token: 0x0600066B RID: 1643
		public abstract void Move(Vector3 deltaPosition, Quaternion deltaRotation);

		// Token: 0x0600066C RID: 1644 RVA: 0x00039F60 File Offset: 0x00038160
		public virtual void Start()
		{
			this.capsule = (base.GetComponent<Collider>() as CapsuleCollider);
			this.r = base.GetComponent<Rigidbody>();
			this.originalHeight = this.capsule.height;
			this.originalCenter = this.capsule.center;
			this.zeroFrictionMaterial = new PhysicMaterial();
			this.zeroFrictionMaterial.dynamicFriction = 0f;
			this.zeroFrictionMaterial.staticFriction = 0f;
			this.zeroFrictionMaterial.frictionCombine = PhysicMaterialCombine.Minimum;
			this.zeroFrictionMaterial.bounciness = 0f;
			this.zeroFrictionMaterial.bounceCombine = PhysicMaterialCombine.Minimum;
			this.highFrictionMaterial = new PhysicMaterial();
			this.r.constraints = RigidbodyConstraints.FreezeRotation;
		}

		// Token: 0x0600066D RID: 1645 RVA: 0x0003A018 File Offset: 0x00038218
		public virtual RaycastHit GetSpherecastHit()
		{
			Vector3 up = base.transform.up;
			Ray ray = new Ray(this.r.position + up * this.airborneThreshold, -up);
			RaycastHit result = default(RaycastHit);
			Physics.SphereCast(ray, this.spherecastRadius, out result, this.airborneThreshold * 2f, this.groundLayers);
			return result;
		}

		// Token: 0x0600066E RID: 1646 RVA: 0x00039A88 File Offset: 0x00037C88
		public float GetAngleFromForward(Vector3 worldDirection)
		{
			Vector3 vector = base.transform.InverseTransformDirection(worldDirection);
			return Mathf.Atan2(vector.x, vector.z) * 57.29578f;
		}

		// Token: 0x0600066F RID: 1647 RVA: 0x0003A08C File Offset: 0x0003828C
		public void RigidbodyRotateAround(Vector3 point, Vector3 axis, float angle)
		{
			Quaternion quaternion = Quaternion.AngleAxis(angle, axis);
			Vector3 point2 = base.transform.position - point;
			this.r.MovePosition(point + quaternion * point2);
			this.r.MoveRotation(quaternion * base.transform.rotation);
		}

		// Token: 0x06000670 RID: 1648 RVA: 0x0003A0E8 File Offset: 0x000382E8
		public void ScaleCapsule(float mlp)
		{
			if (this.capsule.height != this.originalHeight * mlp)
			{
				this.capsule.height = Mathf.MoveTowards(this.capsule.height, this.originalHeight * mlp, Time.deltaTime * 4f);
				this.capsule.center = Vector3.MoveTowards(this.capsule.center, this.originalCenter * mlp, Time.deltaTime * 2f);
			}
		}

		// Token: 0x06000671 RID: 1649 RVA: 0x00006274 File Offset: 0x00004474
		public void HighFriction()
		{
			this.capsule.material = this.highFrictionMaterial;
		}

		// Token: 0x06000672 RID: 1650 RVA: 0x00006287 File Offset: 0x00004487
		public void ZeroFriction()
		{
			this.capsule.material = this.zeroFrictionMaterial;
		}

		// Token: 0x06000673 RID: 1651 RVA: 0x0003A170 File Offset: 0x00038370
		public float GetSlopeDamper(Vector3 velocity, Vector3 groundNormal)
		{
			float num = 90f - Vector3.Angle(velocity, groundNormal);
			num -= this.slopeStartAngle;
			float num2 = this.slopeEndAngle - this.slopeStartAngle;
			return 1f - Mathf.Clamp(num / num2, 0f, 1f);
		}

		// Token: 0x040005B4 RID: 1460
		public const float half = 0.5f;

		// Token: 0x040005B5 RID: 1461
		[Range(1f, 4f)]
		[Header("Base Parameters")]
		[SerializeField]
		public float gravityMultiplier = 2f;

		// Token: 0x040005B6 RID: 1462
		[SerializeField]
		public float airborneThreshold = 0.6f;

		// Token: 0x040005B7 RID: 1463
		[SerializeField]
		public float slopeStartAngle = 50f;

		// Token: 0x040005B8 RID: 1464
		[SerializeField]
		public float slopeEndAngle = 85f;

		// Token: 0x040005B9 RID: 1465
		[SerializeField]
		public float spherecastRadius = 0.1f;

		// Token: 0x040005BA RID: 1466
		[SerializeField]
		public LayerMask groundLayers;

		// Token: 0x040005BB RID: 1467
		public PhysicMaterial zeroFrictionMaterial;

		// Token: 0x040005BC RID: 1468
		public PhysicMaterial highFrictionMaterial;

		// Token: 0x040005BD RID: 1469
		public Rigidbody r;

		// Token: 0x040005BE RID: 1470
		public float originalHeight;

		// Token: 0x040005BF RID: 1471
		public Vector3 originalCenter;

		// Token: 0x040005C0 RID: 1472
		public CapsuleCollider capsule;
	}
}
